package com.hlt.shuiliting.dao;

import java.util.List;
import java.util.Map;

import com.hlt.shuiliting.database.DBUtil;
import com.hlt.shuiliting.valuebean.XiangMuSP;

public class XiangMuSPDAO {

	private int updateCount;
	private int pageCount;
	
	public List list(int GongChengXMID) {
		String sql = "select * from XiangMuSP where GongChengXMID = ?";
		Object[] params = {GongChengXMID};
		DBUtil myDB = new DBUtil();
		myDB.doPstm(sql, params);
		List list = myDB.getResultSet();
		myDB.closed();
		
		return list;
	}
	
	public List list(int GongChengXMID, int pageSize , int pageNum ) {
		String sql = "select * from XiangMuSP where GongChengXMID = ?";
		Object[] params = {GongChengXMID};
		DBUtil myDB = new DBUtil();
		myDB.doPstm(sql, params);
		List list = myDB.getResultSet(pageSize, pageNum);
		pageCount = myDB.getPageCount();
		myDB.closed();
		
		return list;
	}
	
	public Map view(int id) {
		List list = null;
		String sql = "select * from XiangMuSP where ID = ?";
		Object[] params = {id};
		DBUtil myDB = new DBUtil();
		myDB.doPstm(sql, params);
		list = myDB.getResultSet();
		Map map = (Map)list.get(0);
		
		return map;
	}
	public int insert(XiangMuSP XiangMuSP) {
		String sql = "insert into XiangMuSP values (seq_XiangMuSP.nextVal, ?, to_date(?,'yyyy-mm-dd'), ?,?, ?, ?, to_date(?,'yyyy-mm-dd'), ?,?, ?, ?, ?,?)";
		
		String ZhuangTai = XiangMuSP.getZhuangTai();
		String JiLuSJ = XiangMuSP.getJiLuSJ();
		String LuRuR = XiangMuSP.getLuRuR();
		String LeiXing = XiangMuSP.getLeiXing();
		String PiFuWH = XiangMuSP.getPiFuWH();
		String PiWenBT = XiangMuSP.getPiWenBT();
		String PiFuSJ = XiangMuSP.getPiFuSJ();
		String PiFuBM = XiangMuSP.getPiFuBM();
		String TouZiE = XiangMuSP.getTouZiE();
		String WanChengDWMC = XiangMuSP.getWanChengDWMC();
		String FuHeWH = XiangMuSP.getFuHeWH();
		String FuHeJG = XiangMuSP.getFuHeJG();
		String GongChengXMID = XiangMuSP.getGongChengXMID();
		Object[] params = {ZhuangTai, JiLuSJ, LuRuR, LeiXing, PiFuWH, PiWenBT, PiFuSJ, PiFuBM, TouZiE, WanChengDWMC, FuHeWH, FuHeJG, GongChengXMID};
		DBUtil myDB = new DBUtil();
		myDB.doPstm(sql, params);
		updateCount = myDB.getUpdateCount();
		return updateCount;
	}
	
	public int update(XiangMuSP XiangMuSP) {
		String sql = "update XiangMuSP set ZhuangTai = ?, JiLuSJ = to_date(?,'yyyy-mm-dd'), LuRuR = ?, LeiXing = ?, PiFuWH = ?," +
				" PiWenBT = ?, PiFuSJ = to_date(?,'yyyy-mm-dd'), PiFuBM = ?, TouZiE = ?, WanChengDWMC = ?, FuHeWH = ?, FuHeJG = ?, GongChengXMID = ? where ID = ?";
		String ID = XiangMuSP.getID();
		String ZhuangTai = XiangMuSP.getZhuangTai();
		String JiLuSJ = XiangMuSP.getJiLuSJ();
		String LuRuR = XiangMuSP.getLuRuR();
		String LeiXing = XiangMuSP.getLeiXing();
		String PiFuWH = XiangMuSP.getPiFuWH();
		String PiWenBT = XiangMuSP.getPiWenBT();
		String PiFuSJ = XiangMuSP.getPiFuSJ();
		String PiFuBM = XiangMuSP.getPiFuBM();
		String TouZiE = XiangMuSP.getTouZiE();
		String WanChengDWMC = XiangMuSP.getWanChengDWMC();
		String FuHeWH = XiangMuSP.getFuHeWH();
		String FuHeJG = XiangMuSP.getFuHeJG();
		String GongChengXMID = XiangMuSP.getGongChengXMID();
		Object[] params = {ZhuangTai, JiLuSJ, LuRuR, LeiXing, PiFuWH, PiWenBT, PiFuSJ, PiFuBM, TouZiE, WanChengDWMC, FuHeWH, FuHeJG, GongChengXMID, ID};
		DBUtil myDB = new DBUtil();
		myDB.doPstm(sql, params);
		updateCount = myDB.getUpdateCount();
		return updateCount;
	}
	
	public int delete(int id) {
		String sql = "delete from XiangMuSP where ID = ?";
		Object[] params = {id};
		DBUtil myDB = new DBUtil();
		myDB.doPstm(sql, params);
		updateCount = myDB.getUpdateCount();
		return updateCount;
	}
	
	public int getPageCount() {
		return pageCount;
	}
}
